//
//  SinaTabBarViewController.swift
//  SinaWeiBo
//
//  Created by 刘世瑛 on 16/1/19.
//  Copyright © 2016年 刘世瑛. All rights reserved.
//

import UIKit

class SinaTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
      
        UITabBar.appearance().tintColor = UIColor.orangeColor()
    
        //添加子控制器
      addChildViewController()
        //自定义tabbar
        let tabbar = SinaTabBar()
        
        setValue(tabbar, forKey: "tabBar")
        
        
        tabbar.composeButton.addTarget(self, action: "pushLish", forControlEvents: .TouchUpInside)
        // Do any additional setup after loading the view.
    }
    @objc private func pushLish()
    {
    print("---------")
    }
    
    
    
    
    
    //添加子控制器
     func addChildViewController() {
        addChildViewController(SinaHomeTableViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(SinaMessageTableViewController(), title: "消息", image:"tabbar_message_center")
        addChildViewController(SinaFindTableViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(SinaSettingTableViewController(), title: "设置", image: "tabbar_profile")
    }
    
    //封装一个方法
    func addChildViewController(childController: UIViewController,title:String,image:String) {
        let home = childController
        home.title = title
        home.tabBarItem.image = UIImage(named: image)
        home.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        
        let nav = UINavigationController(rootViewController: home)
        
        addChildViewController(nav)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
